/*
package com.burgeon.backend.compinent;


import com.burgeon.backend.SHOP.service.AppPresellService;
import com.burgeon.backend.SHOP.service.GoodsService;
import com.burgeon.backend.SHOP.service.RefundService;
import com.burgeon.backend.SHOPBACKEND.entity.TemplateConfig;
import com.burgeon.backend.SHOPBACKEND.service.*;
import com.burgeon.backend.Util.RunnerDate;
import com.burgeon.backend.mappers.TemplateMapper;
import com.burgeon.backend.service.QueueService;
import com.burgeon.backend.service.RunnerService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

@Component
public class Runner implements CommandLineRunner {

    private final static Log logger = LogFactory.getLog(Runner.class);

    @Autowired
    private RunnerService runnerService;
    @Autowired
    private BackendOrderService backendOrderService;
    @Autowired
    private BackendSeckillService backendSeckillService;
    @Autowired
    private RefundService refundService;
    @Autowired
    private JpushService jpushService;
    @Autowired
    private QueueService queueService;
    @Autowired
    private OrderRateService orderRateService;
    @Autowired
    private BackendActivityService backendActivityService;
    @Autowired
    private AppPresellService appPresellService;
    @Autowired
    private GoodsService goodsService;
    @Autowired
    private BackendGroupService backendGroupService;
    @Autowired
    private BackendBargainService backendBargainService;
    @Autowired
    private TemplateMapper templateMapper;
    @Autowired
    private BackendTemplateService backendTemplateService;
//    @Autowired
//    private RunnerDate runnerDate;

    @Override
    public void run(String... strings) {

        final Timer timerQueue = new Timer();
        timerQueue.schedule(new TimerTask() {
            @Override
            public void run() {
                queueService.consumer();

            }
        }, 5000);


        final Timer timerCode = new Timer();
        timerCode.schedule(new TimerTask() {
            @Override
            public void run() {


                //runnerService.SendConsumptionTemplate(); //发送消费评价模板

                try {
                    runnerService.SendExpenditureTemplate();//消费提醒
                } catch (Exception e) {
                    logger.error(e.getMessage());
                    e.printStackTrace();
                }

                try {
                   runnerService.SendRechargeTemplate();//发送充值提醒
                } catch (Exception e) {
                    logger.error(e.getMessage());
                    e.printStackTrace();
                }


            }
        }, 1000, 1000 * 60 * 60);

        //扫描订单 监听发货状态
        final Timer timerCode1 = new Timer();
        timerCode1.schedule(new TimerTask() {
            @Override
            public void run() {
                try {
                   backendOrderService.QuerryYCRetailout("1");//订单状态值 1为已付款
                } catch (Exception e) {
                    logger.error(e.getMessage());
                    e.printStackTrace();
                }

            }
        }, 1000, 1000 * 60 * 15);

        //123

        final Timer timerCode2 = new Timer();
        timerCode2.schedule(new TimerTask() {
            @Override
            public void run() {
                try {
                    backendSeckillService.timingPutaway();
                } catch (Exception e) {
                    logger.error(e.getMessage());
                    e.printStackTrace();
                }

            }
        }, 1000, 1000 * 60*2);

        final Timer timerCode3 = new Timer();
        timerCode3.schedule(new TimerTask() {
            @Override
            public void run() {
                try {
                    System.err.println("退货开始");
                    refundService.timedTask();
                    System.err.println("退货结束");
                } catch (Exception e) {
                    logger.error(e.getMessage());
                    e.printStackTrace();
                }

            }
        }, 1000, 1000 * 60*2);

        final Timer timerCode4 = new Timer();
        timerCode4.schedule(new TimerTask() {
            @Override
            public void run() {
                try {
                    System.err.println("同步vip");
                    runnerService.synchronizationVipData();
                    System.err.println("同步vip结束");
                } catch (Exception e) {
                    logger.error(e.getMessage());
                    e.printStackTrace();
                }

            }
        }, 1000, 1000 * 60*60*24);

        final Timer timerCode5 = new Timer();
        timerCode5.schedule(new TimerTask() {
            @Override
            public void run() {
                try {
                    jpushService.UmengPushAn();
                } catch (Exception e) {
                    logger.error(e.getMessage());
                    e.printStackTrace();
                }

            }
        }, 1000, 1000 * 60*2);
//
        final Timer timerCode8 = new Timer();
        timerCode8.schedule(new TimerTask() {
            @Override
            public void run() {
                try {
                    SimpleDateFormat sdf = new SimpleDateFormat("HH");
                    String now = sdf.format(new Date());
                    switch (now){
                        case "03":
                            //自动下架0库存商品
                            goodsService.TimingOfTheShelves();
                            break;
                        case "09":
                        case "14":
                        case "11":
                        case "16":
                            jpushService.queryOverTime();
                            jpushService.pushPaiDan();
                            break;
//                            queueService.consumer();
                    }
                } catch (Exception e) {
                    logger.error(e.getMessage());
                    e.printStackTrace();
                }

            }
        }, 1000, 1000 * 60 *60);

 //活动过期

        final Timer timerCode9 = new Timer();
        timerCode9.schedule(new TimerTask() {
            @Override
            public void run() {
                try {
                    backendActivityService.IsUse();
                } catch (Exception e) {
                    logger.error(e.getMessage());
                    e.printStackTrace();
                }

            }
        }, 1000, 1000 * 60*2);

        //开始支付尾款
        final Timer startPayingBalancePayment = new Timer();
        Calendar calendarp = Calendar.getInstance();
        calendarp.set(Calendar.HOUR_OF_DAY,9);
        Date datep = WeKfTemplate(calendarp);
        startPayingBalancePayment.schedule(new TimerTask() {
            @Override
            public void run() {
                try {
                    appPresellService.startPayingBalancePayment();
                } catch (Exception e) {
                    logger.error(e.getMessage());
                    e.printStackTrace();
                }

            }
        }, datep);

        //XX天未评价
        final Timer timerCode6 = new Timer();
        Calendar calendar6 = Calendar.getInstance();
        calendar6.set(Calendar.HOUR_OF_DAY,17);
        calendar6.set(Calendar.MINUTE,34);
        calendar6.set(Calendar.SECOND,30);
        Date date = WeKfTemplate(calendar6);
        timerCode6.schedule(new TimerTask() {
            @Override
            public void run() {
                try {
                    orderRateService.OrderRateTemplate();
//                    System.err.println("定时");
//                    queueService.consumer();
                } catch (Exception e) {
                    logger.error(e.getMessage());
                    e.printStackTrace();
                }

            }
        }, date);

        final Timer timerCode7 = new Timer();
        timerCode7.schedule(new TimerTask() {
            @Override
            public void run() {
                try {
                    backendGroupService.underGroup();//拼团
                } catch (Exception e) {
                    logger.error(e.getMessage());
                    e.printStackTrace();
                }

            }
        }, 1000, 1000 * 60*2);

        final Timer timerCode10 = new Timer();
        timerCode10.schedule(new TimerTask() {
            @Override
            public void run() {
                try {
                    backendBargainService.upUnderTime();//砍价
                } catch (Exception e) {
                    logger.error(e.getMessage());
                    e.printStackTrace();
                }

            }
        }, 1000, 1000 * 60*2);

        //电子券消费模板通知
final Timer expiredCouponTemplate = new Timer();
        RunnerDate aObj = new RunnerDate();
        Field bField = null;
        try {
            bField = aObj.getClass().getDeclaredField("date2");
            bField.setAccessible(true);
            bField.set(aObj, TemplateDate("lfwd"));
            System.err.println(bField.get(aObj)+","+aObj.getDate2());
        } catch (NoSuchFieldException | IllegalAccessException e) {
            e.printStackTrace();
        }
        expiredCouponTemplate.schedule(new TimerTask() {
            @Override
            public void run() {
                try {
                    TemplateConfig templateConfig = templateMapper.GetTemplate8("lfwd");
                    System.err.println("fdddddd");
                    backendTemplateService.GetExpiredCouponTemplate(templateConfig);
                } catch (Exception e) {
                    logger.error(e.getMessage());
                    e.printStackTrace();
                }

            }
        },aObj.getDate2());

        //未发货超时通知店铺导购
//        final Timer timerCode6 = new Timer();
//        timerCode6.schedule(new TimerTask() {
//            @Override
//            public void run() {
//                try {
//                   // jpushService.queryOverTime();
//                } catch (Exception e) {
//                    logger.error(e.getMessage());
//                    e.printStackTrace();
//                }
//
//            }
//        }, 1000, 1000 * 60 * 5);
//
//        //手工分单
//        final Timer timerCode7 = new Timer();
//        timerCode7.schedule(new TimerTask() {
//            @Override
//            public void run() {
//                try {
//                   // jpushService.pushPaiDan();
//                } catch (Exception e) {
//                    logger.error(e.getMessage());
//                    e.printStackTrace();
//                }
//
//            }
//        }, 1000, 1000 * 60 * 3);
    }


    public Date TemplateDate(String token){
        TemplateConfig templateConfig = templateMapper.GetTemplate8(token);
        System.err.println(templateConfig);
        Calendar calendar7 = Calendar.getInstance();
        //获取发送时间
        calendar7.set(Calendar.HOUR_OF_DAY,Integer.parseInt(templateConfig.getSendTime()));
        Date date1=calendar7.getTime(); //第一次执行定时任务的时间
        if (date1.before(new Date())) {
            date1 = this.addDay(date1, 1);
        }
        System.out.println(date1);
        return date1;

    }
    private Date WeKfTemplate(Calendar calendar){


        Date date=calendar.getTime(); //第一次执行定时任务的时间
        if (date.before(new Date())) {
            date = this.addDay(date, 1);
        }

        return date;

    }

    // 增加或减少天数
    private Date addDay(Date date, int num) {
        Calendar startDT = Calendar.getInstance();
        startDT.setTime(date);
        startDT.add(Calendar.DAY_OF_MONTH, num);
        return startDT.getTime();
    }


}

*/
